package remote

import (
	"RedWork/model"
	"RedWork/rpc"
	"github.com/gin-gonic/gin"
	"log"
)

func RpcUserRegister() gin.HandlerFunc {
	return func(c *gin.Context) {
		log.Println("if enter_____________")
		username := c.PostForm("username")
		password := c.PostForm("password")
		//用etcd找服务
		ctl := rpc.NewUserLrCtl("127.0.0.1:2379", "jingdong/user")
		res := ctl.CallRegister(model.UserInfo{
			UserName: username,
			PassWord: password,
		})
		c.JSON(200, res)
	}
}

func RpcLogin() gin.HandlerFunc {
	return func(c *gin.Context) {
		username := c.PostForm("username")
		password := c.PostForm("password")
		//用etcd找服务
		ctl := rpc.NewUserLrCtl("127.0.0.1:2379", "jingdong/user")
		res := ctl.CallLogin(model.UserInfo{
			UserName: username,
			PassWord: password,
		})
		c.JSON(200, res)
	}
}

func RpcChangePw() gin.HandlerFunc {
	return func(c *gin.Context) {
		token := c.PostForm("token")
		newPW := c.PostForm("new")
		res := rpc.CallChangePw("127.0.0.1:50002", token, newPW)
		c.JSON(200, res)
	}
}
